<template>
    <div class="paint_brush_container">
        <div>画笔粗细</div>
        <div class="item_group">
            <div class="paint_brush_width" :style="{
                width: lineWidth * 1.5 + 'px',
                height: lineWidth * 1.5 + 'px',
            }"></div>
            <input type="range" class="input_range" :value="lineWidth"
                @input="clickButtonHandler('width', ($event.target as any).value)" max="20" min="1" />
        </div>
        <div>画笔颜色</div>
        <div class="item_group">
            <div :class="['paint_brush_color', index == activeColor ? 'activeColor' : '']"
                v-for="(item, index) in paintBrushColor" :style="{ background: item }"
                @click="clickButtonHandler('color', item, index)"></div>
        </div>
        <div>画笔类型</div>
        <div class="item_group">
            <div :class="['paint_brush_type', index == activeType ? 'activeType' : '']"
                v-for="(item, index) in paintBrushType" @click="clickButtonHandler('lineType', item, index)">
                {{ item }}</div>
        </div>
    </div>
</template>

<script setup lang='ts'>
import {
    paintBrushColor, paintBrushType, lineWidth, activeColor, activeType
} from './data';

const emits = defineEmits(["clickPaintBrushBtn"])

const clickButtonHandler = (type: string, item?: string, index?: number) => {
    const objectHandler: Record<string, () => void> = {
        color: () => {
            emits("clickPaintBrushBtn", "color", item, index);
        },
        width: () => {
            emits("clickPaintBrushBtn", "width", item);
        },
        lineType: () => {
            emits("clickPaintBrushBtn", "lineType", ['pen', 'fluorescence'][index!], index);
        }
    }
    objectHandler[type]()
}
</script>

<style scoped lang="scss">
.paint_brush_container {
    position: absolute;
    left: 125px;
    padding: 10px;
    margin: 0;
    box-shadow: 2px 2px 10px 1px rgba(18, 18, 20, 0.38);
    background-color: #fff;
    border-radius: 8px;
    width: 250px;

    .item_group {
        display: flex;
        justify-content: space-between;
        flex-wrap: wrap;
        margin: 15px 0;

        .paint_brush_width {
            margin: auto 10px;
            background-color: #000000;
            border-radius: 50%;
        }

        .paint_brush_color {
            width: 25px;
            height: 25px;
            border-radius: 50%;
        }

        .activeColor {
            position: relative;
            border: 1px solid transparent;

            &::before {
                content: "";
                position: absolute;
                width: 14px;
                height: 14px;
                top: 3px;
                left: 3px;
                border-radius: 50%;
                border: 3px solid #eee;
            }
        }

        .paint_brush_type {
            width: 21%;
            text-align: center;
            box-sizing: border-box;
            border: 1px solid transparent;
            border-radius: 50%;
            line-height: 20px;
            height: 26px;
            font-size: 24px;
            font-size: 14px;
        }

        .activeType {
            border: 1px solid #ccc;
        }

        .line {
            width: 1px;
            height: 28px;
            background-color: #ddd;
        }
    }
}

.input_range {
    appearance: none;
    width: 200px;
    height: 15px;
    border-radius: 10px;
    border: none;
    outline: none;
    position: relative;
    margin: 0;

    &::before {
        content: '';
        position: absolute;
        width: 100%;
        height: 100%;
        left: 0;
        top: 1px;
        background-color: rgb(216, 234, 250);
        clip-path: polygon(0% 50%, 95% 0, 95% 100%);
    }

    &::-webkit-slider-runnable-track {
        -webkit-appearance: none;
    }

    &::-webkit-slider-thumb {
        -webkit-appearance: none;
        height: 20px;
        width: 20px;
        background: #ffffff;
        border-radius: 50%;
        z-index: 10;
        position: relative;
        cursor: pointer;
        border: 2px solid #ddd;
    }
}
</style>